<extend name="Common@common:layui" />
<block name="title">
    <title>选取文章</title>
</block>
<block name="style">
    <style>
        body {
            padding: 10px;
        }
    </style>
</block>

<block name="main">
    <div class="my-btn-box layui-clear">
        <span style="float:right">
            <form action="/admin/page/article_select" method="GET" class="layui-form">
                <div class="layui-form-item">
                    <label class="layui-form-label">搜索标题：</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keyword" required lay-verify="required" value="{$_GET['keyword']}" placeholder="请输入标题" autocomplete="off" class="layui-input">
                    </div>
                    <button type="submit" class="layui-btn" lay-submit lay-filter="formDemo">搜索</button>
                </div>
            </form>
            <php>
                if($_GET['keyword']){ 
                    $conditionStr = "type=title&keyword=".$_GET['keyword'];
                    $strToRed = 'param-title'.":".$_GET['keyword'];
                }
            </php>
	    </span>
    </div>
    <form class="selectMulti">
    <div class="layui-form datashow" data-url="/admin/content/getdata/group/content/cid/{$_GET['catsId']}" data-to-red="{$strToRed}" data-condition="{$conditionStr}" data-p="1" data-row="10">
        <table class="layui-table">
            <colgroup>
                <col width="50">
                <col width="60">
                <col>
                <col>
                <col>
                <col>
                <col>
                <col>
                <col width="140">
            </colgroup>
            <thead>
                <tr>
                    <th><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
                    <th>ID</th>
                    <th>标题</th>
                    <th>作者</th>
                    <th>封面图</th>
                    <th>点击量</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody class="data"></tbody>
        </table>
        <div class="page"></div>
        <script class="data-tpl" type="text/html">
            {{# layui.each(d, function(index, item){ }}
            <tr>
                <td><input type="checkbox" name="ids[]" value="{{item.id}}" lay-skin="primary">
                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                </td>
                <td class="param-id">{{item.id}}</td>
                <td><a class="param-title" href="/content/Article/detail/id/{{item.id}}" target="_blank">{{item.title}} </a></td>
                <td class="param-author">{{item.realname || "无"}}  </td>
                <td class="param-fengmian"><img src="{{item.fengmian||'http://s1.ajplaychina.com/image/2017-05/2017-05-27/149587823165524(240x180).jpg'}}" style="width:50px;height:50px"></td>

                <td>{{item.click_count}}</td>
                <td>{{item.create_time}}</td>
                <td>{{item.update_time}}</td>

                <td>
                    <div class="layui-btn-group">
                        <button class="layui-btn layui-btn-sm layui-btn-normal" type="button" data-id="{{item.id}}" onclick="book_select({{item.id}},'{{item.title}}','{{item.author}}','{{item.content.stripHTML().substr(0,200)}}','{{item.create_time}}')">选择</button>
                    </div>
                </td>
            </tr>
            {{# }); }} {{# if(d.length === 0){ }}
            <tr>
                <td colspan="9" style="text-align:center;">--- No Data ---</td>
            </tr>{{# } }}
        </script>
    </div>
    </form>
</block>

<block name="script">
    <script>
        function book_select(id, title,author,content,create_time) {
            layui.use(['jquery', 'layer'], function() {
                var $ = layui.jquery,
                    layer = layui.layer;
                var asker = layer.confirm('确定选择吗？', function() {
                    var articleData = {"id":id,"title":title,"author":author,"content":content,"create_time":create_time};
                    parent.callback_select(articleData);
                });
            });
        }
        String.prototype.stripHTML = function() {
            var reTag = /<(?:.|\s)*?>/g;
            return this.replace(reTag,"");
        }
    </script>
</block>